using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ColladaXna.Base.Materials
{
    public class Material
    {
        protected List<MaterialProperty> _properties = new List<MaterialProperty>();

        public List<MaterialProperty> Properties
        {
            get { return _properties; }
        }

        public String Name { get; set; }        

        public Material()
        {
            
        }

        public Material(String name, params MaterialProperty[] properties)
            : this(name, properties as IEnumerable<MaterialProperty>)
        {
            
        }

        public Material(params MaterialProperty[] properties)
            : this(String.Empty, properties)
        {
            
        }

        public Material(String name, IEnumerable<MaterialProperty> properties)
        {
            this.Name = name;
            _properties.AddRange(properties);
        }

        /// <summary>
        /// Generates an unique ID-String for this material based on the used
        /// material properties. This is used to distinguish different effect
        /// classes, for example all effects using a diffuse texture and a 
        /// normal map (the resulting ID in this case would be "NT").
        /// The id is generated by concatenating each material property's
        /// Code (MaterialProperty.Code), which consist of one or two characters, 
        /// in alphabetical order.
        /// </summary>
        /// <returns></returns>
        public String GenerateId()
        {
            var codes = from p in _properties orderby p.Code select p.Code;
            string id = "";
            foreach (string code in codes)
                id += code;

            return id;
        }        
    }
}
